#!/usr/bin/perl
use strict;
use warnings;

my $arg_num = @ARGV;

#check parameter
if ($arg_num != 1)
{
    print "usage:$0 c_source_file\n";
    exit 1;
}

my $input_file = $ARGV[0];
my $prefix_name;

if ($input_file =~ /\//)
{
    $input_file =~ /.*\/(.*)\.c/;
    $prefix_name = $1;
}
else
{
    $input_file =~ /(.+)\.c/;
    $prefix_name = $1;
}

my $asm_file_name = $prefix_name.".asm";
my $obj_file_name = $prefix_name.".o";

`./cminus-compiler -o $asm_file_name -f $input_file`;
`nasm -f elf $asm_file_name`;
`gcc -o $prefix_name $obj_file_name`;

print "Now you can type \'./$prefix_name\' to run this program!\n";
print "Now you can type \'vim $asm_file_name\' to see generated asm file!\n";
